var sortList = function(head) {
  var merge = function(lnode) {
    if(lnode === null || lnode.next === null) return lnode
    let slow = lnode, fast = lnode.next
    while(fast && fast.next) {
      slow = slow.next
      fast = fast.next.next
    }
    let tmp = slow.next
    slow.next = null
    let l1 = merge(lnode)
    let l2 = merge(tmp)
    return sort(l1, l2)
  }
  return merge(head)
}
function sort(l1, l2) {
  let dummy = new ListNode()
  let pre = dummy
  let p1 = l1, p2 = l2
  while(p1 && p2) {
    if(p1.val < p2.val) {
      pre.next = p1
      p1 = p1.next
    } else {
      pre.next = p2
      p2 = p2.next
    }
    pre = pre.next
  }
  if(p1) pre.next = p1
  if(p2) pre.next = p2
  return dummy.next
}